package com.ruoyi.web.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SuperFlashSale;
import com.ruoyi.system.service.ISuperFlashSaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 限时抢购Controller
 * 
 * @author xjf
 * @date 2025-08-13
 */
@RestController
@RequestMapping("/activity/sale")
public class SuperFlashSaleController extends BaseController
{
    @Autowired
    private ISuperFlashSaleService superFlashSaleService;

    /**
     * 查询限时抢购列表
     */
    @PreAuthorize("@ss.hasPermi('activity:sale:list')")
    @GetMapping("/list")
    public TableDataInfo list(SuperFlashSale superFlashSale)
    {
        startPage();
        List<SuperFlashSale> list = superFlashSaleService.selectSuperFlashSaleList(superFlashSale);
        return getDataTable(list);
    }

    /**
     * 导出限时抢购列表
     */
    @PreAuthorize("@ss.hasPermi('activity:sale:export')")
    @Log(title = "限时抢购", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SuperFlashSale superFlashSale)
    {
        List<SuperFlashSale> list = superFlashSaleService.selectSuperFlashSaleList(superFlashSale);
        ExcelUtil<SuperFlashSale> util = new ExcelUtil<SuperFlashSale>(SuperFlashSale.class);
        util.exportExcel(response, list, "限时抢购数据");
    }

    /**
     * 获取限时抢购详细信息
     */
    @PreAuthorize("@ss.hasPermi('activity:sale:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(superFlashSaleService.selectSuperFlashSaleById(id));
    }

    /**
     * 新增限时抢购
     */
    @PreAuthorize("@ss.hasPermi('activity:sale:add')")
    @Log(title = "限时抢购", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SuperFlashSale superFlashSale)
    {
        return toAjax(superFlashSaleService.insertSuperFlashSale(superFlashSale));
    }

    /**
     * 修改限时抢购
     */
    @PreAuthorize("@ss.hasPermi('activity:sale:edit')")
    @Log(title = "限时抢购", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SuperFlashSale superFlashSale)
    {
        return toAjax(superFlashSaleService.updateSuperFlashSale(superFlashSale));
    }

    /**
     * 删除限时抢购
     */
    @PreAuthorize("@ss.hasPermi('activity:sale:remove')")
    @Log(title = "限时抢购", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(superFlashSaleService.deleteSuperFlashSaleByIds(ids));
    }
}
